package com.qiqu.controller;


import com.qiqu.commen.Const;
import com.qiqu.entity.UsersFans;
import com.qiqu.service.UsersFansService;
import com.qiqu.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.qiqu.commen.Const.PAGE_SIZE;

@RestController
@RequestMapping("usersFans")
@Api(value = "粉丝相关接口",tags = {"粉丝相关接口controller"})
public class UsersFansController {
    @Resource
    private UsersFansService usersFansService;

    //关注
    @ApiOperation(value = "关注用户--sora", notes = "关注用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "fanId", value = "关注的人的id", required = true, dataType = "string", paramType = "query")
    })
    @PostMapping("/fan")
    public JSONResult Fans(@RequestBody UsersFans usersFans) {

        return JSONResult.ok(usersFansService.Fan(usersFans.getUserId(),usersFans.getFanId()));
    }

    //取消关注
    @ApiOperation(value = "取消关注--sora", notes = "取消")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "fanId", value = "关注的人的id", required = true, dataType = "string", paramType = "query")
    })
    @PostMapping("/cancleFan")
    public JSONResult cancleFans(@RequestBody UsersFans usersFans) {
        return JSONResult.ok(usersFansService.cancleFan(usersFans.getUserId(),usersFans.getFanId()));
    }

    //是否已经关注
    @ApiOperation(value = "是否已经关注--fk", notes = "是否已经关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "fanId", value = "关注的人的id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/isFan")
    public JSONResult isFan(String userId,String fanId) {
        return  JSONResult.ok(usersFansService.isFan(userId,fanId));
    }

    //获取用户被关注信息
    @ApiOperation(value = "获取用户被关注信息--fk",notes = "获取用户被关注信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="page",value = "页码",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query"),
    })
    @GetMapping("/getFans")
    public JSONResult getFans(Integer page,String userId) {
        if(page == null){
            page=1;
        }
        return JSONResult.ok(usersFansService.getFans(page,PAGE_SIZE,userId));
    }

    //获取未读关注信息数
    @ApiOperation(value = "获取未读关注信息数--fk",notes = "获取未读关注信息数")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/getFanCounts")
    public JSONResult getFanCounts(String userId) {
       // System.out.println(userId);
        return JSONResult.ok(usersFansService.queryStatusCount(userId));
    }

    //更新状态信息
    @ApiOperation(value = "更新状态信息--fk",notes = "更新状态信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/updateFan")
    public JSONResult updateFan(String userId) {
        return JSONResult.ok(usersFansService.updateStatus(userId));
    }

}